package main

import (
	"fmt"

	"database/sql"

	_ "github.com/go-sql-driver/mysql"

	jet "github.com/go-jet/jet/v2/mysql"
	"github.com/hui/hello-jet/db/model"
	"github.com/hui/hello-jet/db/table"
)

func main() {
	start()
}

func start() {
	// Connect to database
	connectString := "dev-user:dev-user@tcp(127.0.0.1:3306)/spring_boot_dev?parseTime=true&loc=Asia%2FShanghai&charset=utf8"

	db, err := sql.Open("mysql", connectString)
	panicOnError(err)
	defer db.Close()

	var users []model.User

	stmt := jet.SELECT(
		table.User.ID,
		table.User.Username,
	).FROM(table.User)

	fmt.Println(stmt.Sql())

	stmt.Query(db, &users)

	println(users)
}

func panicOnError(err error) {
	if err != nil {
		panic(err)
	}
}
